$(function () {
	provinceInfo.baseURL = baseURL;
	provinceInfo.divId = "test";
	provinceInfo.init();
	provinceInfo.bindEvent();
	$('#_province').val(engineerProvincecode(engineer.provincecode));
	$('#_city').val(engineer.city);
	$('#_city').attr('name',engineer.citycode);
	$('#usename').val(engineer.username);
    $('#source').val(engineerSource(engineer.source));
    $('#name').val(engineer.name);
    $('#sex').val(engineer.sex);
    $('#mobile').val(engineer.mobile);
    $('#qq').val(engineer.qq);
    $('#email').val(engineer.email);
    $('#company').val(engineer.company);
    $('#companyAddress').val(engineer.companyAddress);
    $('#clientRemark').val(engineer.clientRemark);
    function engineerSource(obj){
    	if(obj=="1"){
    		return "论坛";
    	}else return "咨询";
    }
    function engineerProvincecode(obj){
    	var province;
    	$.each($('#_province').next().find('li'),function(i,n){
    		if($(n).attr('id')==obj){
    			$('#_province').attr("name",obj);
    			province=$(n).text();
    		}
    	})
    	return province;
    }
    $("#form-add").Validform({
        tiptype: 1,
        showAllError: true,
        datatype: {
            "empty": /^\s*$/,
            "code": /^[a-z0-9A-Z_-]{1,16}$/
        },
        callback: function (form) {
            layer.confirm('您确定要提交表单吗?', function () {
                _submit();
            })
            return false;
        }
    });
})

_submit = function () {
    var data = {};
    data.id=engineer.id;
    data.provincecode = $('#_province').attr('name');
	data.citycode = $('#_city').attr('name');
    data.province = $('#_province').val();
	data.city = $('#_city').val();
    data.username = $('#usename').val();
    data.source = engineerSource($('#source').val());
    data.name = $('#name').val();
    data.sex = $('#sex').val();
    data.mobile = $('#mobile').val();
    data.qq = $('#qq').val();
    data.email = $('#email').val();
    data.company = $('#company').val();
    data.companyAddress = $('#companyAddress').val();
    data.clientRemark = $('#clientRemark').val();
    function engineerSource(obj){
    	if(obj=="论坛"){
    		return "1";
    	}else return "2";
    }
    $.ajax({
        type: "post",
        url: baseURL + '/api/member/saveOrgUpdateEngineer',
        dataType: "json",
        contentType: "application/json;charset=UTF-8", 
        data: JSON.stringify(data),
        success: function (result) {
            if (!result.flag) {
                layer.msg("增加失败！原因：" + result.message);
                return;
            }
            parent.location.reload();
            window.close();
        }
    });
}